package com.yami.shop.multishop.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.UserAddr;
import com.yami.shop.bean.model.VrScene;
import com.yami.shop.bean.model.VrSceneDetail;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.multishop.util.SecurityUtils;
import com.yami.shop.service.VrSceneDetailService;
import com.yami.shop.service.VrSceneService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Date;

/**
 * @author lth
 */
@RestController
@AllArgsConstructor
@RequestMapping("/shop/vrScene")
@Tag(name="店铺工商信息接口")
public class VrSceneController {
    private final VrSceneService vrSceneService;

    @PostMapping
    @Operation(summary =  "新增场景", description = "新增场景信息")
    public ServerResponseEntity<Void> save(@Valid @RequestBody VrScene tzVrScene) {
        Long shopId = SecurityUtils.getShopUser().getShopId();
        tzVrScene.setShopId(shopId);
        tzVrScene.setStatus("1");
        tzVrScene.setCreateTime(new Date());
        vrSceneService.saveVrScene(tzVrScene);
        return ServerResponseEntity.success();
    }

    @PutMapping
    @Operation(summary =  "更新场景信息", description = "更新场景信息")
    public ServerResponseEntity<Void> update(@Valid @RequestBody VrScene tzVrScene) {
        Long shopId = SecurityUtils.getShopUser().getShopId();
        tzVrScene.setShopId(shopId);
        vrSceneService.updateVrScene(tzVrScene);
        return ServerResponseEntity.success();
    }

    @PutMapping("/pulish")
    @Operation(summary =  "更新场景信息", description = "更新场景信息")
    public ServerResponseEntity<Void> pulish(@Valid @RequestBody VrScene tzVrScene) {
        tzVrScene.setUpdateTime(new Date());
        vrSceneService.updateById(tzVrScene);
        return ServerResponseEntity.success();
    }

    @GetMapping("/info/{id}")
    @Operation(summary =  "通过id查询场景管理", description = "通过id查询用场景管理")
    public ServerResponseEntity<VrScene> getById(@PathVariable("id") Long id) {
        return ServerResponseEntity.success(vrSceneService.getInfoById(id));
    }
    /**
     * 分页查询
     *
     * @param page     分页对象
     * @return 分页数据
     */
    @GetMapping("/page")
    @Operation(summary =  "分页查询场景", description = "分页查询场景")
    public ServerResponseEntity<IPage<VrScene>> getVrScenePage(PageParam<VrScene> page, @ParameterObject VrScene vrScene) {
        return ServerResponseEntity.success(vrSceneService.page(page, new LambdaQueryWrapper<VrScene>()
                .like(StrUtil.isNotEmpty(vrScene.getSceneName()), VrScene::getSceneName, vrScene.getSceneName())
                .ne(VrScene::getStatus, "2").orderByDesc(VrScene::getCreateTime)));
    }
    /**
     * 通过id删除场景管理
     *
     * @param  id
     * @return 是否删除成功
     */
    @SysLog("删除场景管理")
    @DeleteMapping("/{id}")
    @Operation(summary =  "通过id删除场景管理", description = "通过id删除场景管理")
    public ServerResponseEntity removeById(@PathVariable Long id) {
        vrSceneService.removeVrSceneById(id);
        return ServerResponseEntity.success();
    }
}
